package de.hwrberlin.remo.logging;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.widgets.Display;

public class MessageStylingBuilder {
	
	private final static String[] LOGGING_LEVELS = new String[] 
	                                      { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" };
	
	public StyleRange buildStyleForMessage(String message) {
		StyleRange styleRange = new StyleRange();
		styleRange.length = 8;
		
		if(message.startsWith("[" + LOGGING_LEVELS[0])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
			
		} else if(message.startsWith("[" + LOGGING_LEVELS[1])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
		
		} else if(message.startsWith("[" + LOGGING_LEVELS[2])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
		
		} else if(message.startsWith("[" + LOGGING_LEVELS[3])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_YELLOW);
		
		} else if(message.startsWith("[" + LOGGING_LEVELS[4])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW);
		
		} else if(message.startsWith("[" + LOGGING_LEVELS[5])) {
			styleRange.foreground = Display.getDefault().getSystemColor(SWT.COLOR_RED);
			styleRange.underline  = true;
		} 
		
		return styleRange;
	}
}